<?php

abstract class AbstractGuest extends UsersAppModel
{
	var $name = 'Guest';
	
	var $validate = array('email'=>array('rule'=>VALID_NOT_EMPTY,'required'=>1),
							'confirm_email' =>array('rule'=>VALID_NOT_EMPTY,'required'=>1));
	var $fieldProperties = array(
		'name' => array(
			'type' => 'text',
			'group' => 'add',
			'class'=>'required',
			'maxlength'=>'30'
		),	
		'email' => array(
			'type' => 'text',
			'group' => 'add',
			'class'=>'email required',
			'maxlength'=>'50'
		),
		'confirm_email' => array(
			'type' => 'text',
			'group' => 'add',
			'class'=>'required',
			'maxlength'=>'50'
		),
		
	);	
		
	function beforeValidate($options = array())
	{
		if(isset($this->data[$this->alias]['email']) && isset($this->data[$this->alias]['confirm_email']) && $this->data[$this->alias]['email']  != $this->data[$this->alias]['confirm_email'] )
		{
			$this->invalidate('confirm_email',__('Confirm email do not match with email'));
			return false;
		}
		return parent::beforeValidate($options);
	}
	function full_name($record)
	{
		return $record['Guest']['name'];
	}
	
	function profile_url($record)
	{
		return '#';
	}
	
	function beforeSave($options)
	{
		if($this->_isNew())
		{
			$this->data[$this->alias]['validateCode']  = Security::hash(time().'_'.rand(),null,null);
			$this->data[$this->alias]['status'] = 1; 
		}
		return parent::beforeSave($options);
	}
}
?>